[#macro articleUpdateView]
<div class="model-form">
    <el-page-header @back="goBack" content="更新文章">
    </el-page-header>
    <div class="model-content">
        <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
            <el-row :gutter="10">
                <el-col :span="22">
                    <el-form-item label="标题" size="mini" prop="title">
                        <el-input v-model="form.title" name="title">
                        </el-input>
                    </el-form-item>

                </el-col>
                <el-col :span="22">
                    <el-form-item label="封面" size="mini" prop="logo">
                        <avatar v-model="form.logo"></avatar>
                    </el-form-item>

                </el-col>
                <el-col :span="22">
                    <el-form-item label="文章分类" size="mini" prop="articleCatalog">
                        <el-select style="width: 100%;" v-model="form.articleCatalog" filterable clearable
                            placeholder="请选择">
                            <el-option v-for="item in articleCatalogOptions" :key="item.id" :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>

                </el-col>
                <el-col :span="22">
                    <div style="margin-left: 160px;">
                        <div id="uenote" name="note" type="text/plain"></div>
                    </div>

                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22" style="text-align: right;padding-bottom: 20px;padding-top: 20px;">
                    <el-button @click="goBack">取消</el-button>
                    <el-button type="primary" @click="updateData">确定</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</div>
[/#macro]

[#macro articleUpdateConfig]
<script type="text/x-template" id="my-article-update">
    [@articleUpdateView /]
</script>
<script type="text/javascript">
    //更新组件开始
    var uenote;
    var articleUpdateConfig = {};
    articleUpdateConfig.template = "#my-article-update";
    articleUpdateConfig.methods = config.basicMethod();
    articleUpdateConfig.methods.updateData = function () {
        var self = this;
        this.$refs["ruleForm"].validate(function (valid) {
            if (valid) {
                self.updateDataPost();
            } else {
                console.log('error submit!!');
                return false;
            }
        });
    }

    articleUpdateConfig.methods.updateDataPost = function () {
        var self = this, data = this.form;
        //delete data.articleCatalog;
        if (this.deforeUpdateData) {
            this.deforeUpdateData();
        }
        if (uenote) {
            data.note = uenote.getContent();
        }
        this.postData("${siteurl}tenantRest/article/update.htm", data, function (res) {
            if (res.code == 0) {
                self.$message({
                    message: '修改数据成功',
                    type: 'success'
                });
                //window.history.go(-1)
                self.$router.go(-1);
            } else {
                self.$message.error(res.msg);
            }
        });
    }
    articleUpdateConfig.data = function () {
        return {
            form: {
                title: '',
                logo: '',
                articleCatalog: '',
                note: ''
            },
            rules: {
                title: [
                    { required: true, message: '请输入标题', trigger: 'blur' }
                ],
                logo: [
                    { required: true, message: '请输入封面', trigger: 'blur' }
                ],
            }
        }
    };

    articleUpdateConfig.mounted = function () {
        var id = this.$route.query.id;
        var self = this;
        var data = {};
        data.id = id;
        this.postData("${siteurl}tenantRest/article/view.htm", data, function (res) {
            if (res.code == 0) {
                self.form = res;
                uenote = initEditor("uenote");;
                uenote.ready(function () {
                    //设置编辑器的内容
                    uenote.setContent(res.note);
                });
            }
        });
    }
    articleUpdateConfig.computed = {};
    articleUpdateConfig.computed.articleCatalogOptions = function () {
        return this.$store.state.articleCatalogOptions;
    };

    articleUpdateConfig.destroyed = function () {
        console.log("destroyed add view ");

        UE.getEditor('uenote').destroy();
    }
    var articleUpdateView = Vue.component('update-view', articleUpdateConfig);
    //更新组件结束
</script>
[/#macro]